home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / STRINGS.SWG / 0103_commas in longint.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  1KB  |  29 lines

  1. {
  2.  MH> the output something like "12,345,678,910"
  3.  KH>                            ^^^^12 Gigs huh?
  4.  MH> Would anyone be able to tell me how to format the output like that?
  5.  KH>
  6.  KH> The only way I can think of is writing a procedure to do so. It's a
  7.  KH> real  pain in the *ss if you know what I mean. I had to write a program
  8. }
  9. type
  10.  st14=string[14];
  11. Function Commas(n:longint):st14;
  12. var
  13.  stopat, {stop bound at left of string}
  14.  npos:byte; {numeric position in string}
  15.  tmp:st14; {temporary}
  16. begin
  17.  str(n,tmp); {convert to string}
  18.  npos:=length(tmp); {set length for counter}
  19.  if tmp[1]='-' then stopat:=2 else stopat:=1; {set stop bound, compensate
  20.                                               for negatives}
  21.  while npos>stopat do begin {while commas needed}
  22.   {insert a comma if needed}
  23.   if (length(tmp)-npos=2) or (pos(',',tmp)-npos=3)
  24.    then insert(',',tmp,npos);
  25.   dec(npos); {always decrease string position until StopAt bound reached}
  26.  end;
  27.  commas:=tmp; {result=temporary string}
  28. end;
  29.